﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;
using System.Data;

namespace Automobile.service.UI
{
    public partial class UpdateProduct : System.Web.UI.Page
    {
        ProductBll bll = new ProductBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["fid"] != null)
                {
                    LoadData();
                }
            }
        }

        private void LoadData()
        {
            this.TextBox1.Text = Request.QueryString["fid"].ToString();

            DataTable dt = bll.GetProduct(this.TextBox1.Text);
            if (dt != null)
            {
                this.TextBox1.Text = dt.Rows[0][1].ToString();
                this.TextBox2.Text = dt.Rows[0][2].ToString();
                this.TextBox3.Text = dt.Rows[0][3].ToString();
                this.TextBox4.Text = dt.Rows[0][4].ToString();
                this.TextBox5.Text = dt.Rows[0][5].ToString();
                this.TextBox6.Text = dt.Rows[0][6].ToString();
                this.TextBox7.Text = dt.Rows[0][7].ToString();
                this.TextBox8.Text = dt.Rows[0][8].ToString();
                this.TextBox9.Text = dt.Rows[0][9].ToString();
            }
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("Product.aspx");  //页面跳转
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            ProductModel model = new ProductModel();
            model.Product_Id = Convert.ToInt32(this.TextBox10.Text);
            model.Product_Name = TextBox1.Text;
            model.Product_Modelspe = TextBox2.Text;
            model.Product_Bprid = Convert.ToDecimal(this.TextBox3.Text);
            model.Product_Price = Convert.ToDecimal(this.TextBox4.Text);
            model.Product_Type_Id = Convert.ToInt32(this.TextBox5.Text);
            model.Product_Barcode = TextBox6.Text;
            model.Product_frim = TextBox7.Text;
            model.Product_Unit_Id = TextBox8.Text;
            model.Product_Remark = TextBox9.Text;
            if (bll.UpdateProduct(model) > 0)
            {
                Response.Write("<script>alert('商品信息修改成功!');location.href='Product.aspx';</script>");
            }
        }


    }
}